<template>
	<view class="container">
		<view class="upload" v-if="avatar">
			<text>头像：</text>
			<view class="box">
			</view>
			<button type="default" @click="go">登录</button>
		</view>
		<view class="upload" v-else>
			<view class="box">
				<image class="box-img" :src="'http://localhost:8090'+user.icon" @click="uploadiamge"></image>
			</view>
			<uni-list>
				<uni-list-item title="修改密码" note="" ></uni-list-item>
				<uni-list-item title="电话" note="" :rightText="user.telephone"></uni-list-item>
			</uni-list>
			<button type="default" @click="exit">退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: true,
				user:{
					icon:""
				},
				a:'123',
			}
		},
		methods: {
			exit(){
				uni.removeStorage({
					key:'user'
				})
				uni.clearStorageSync(
				
				)
				this.user={},
				this.avatar=true
			},
			uploadiamge() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						console.log("res",res.tempFilePaths[0]);
						console.log("res",res);
						console.log("tempFilePaths",res.tempFilePaths);
						uni.uploadFile({
							url: 'http://localhost:8090/foodapp/uploadheadicon',
							filePath:res.tempFilePaths[0],
							formData:{
								id:this.user.id
							},
							name: 'file',
							success:(uploadFileRes)=> {
								console.log('uploadFileRes',uploadFileRes)
								let person=JSON.parse(uploadFileRes.data)
								this.user.icon=person.headiconpath
							}
						});
					}
				})
			},
			go() {
				uni.navigateTo({
					url: '/pages/my/login/login'
				})
			},
			getUser(){
				uni.getStorage({
					key: 'user',
					success:  res=> {
						console.log("res",res.data);
						this.user=res.data
						console.log("123",this.user);
						this.avatar=false
					},
				});
				
			}
		},
		onShow(){
			this.getUser()
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}

	.box {
		width: 80px;
		height: 80px;
		border-radius: 50%;
		background-color: antiquewhite;
	}
	.box-img{
		width: 80px;
		height: 80px;
	}
</style>
